package com.jxm.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author: jxm
 * @Description: 两个通道之间的传输 transferTo
 * @Date: 2024-2-7 14:33
 * @Version: 1.0
 */
public class FileChannelDemo4 {

    public static void main(String[] args) throws IOException {
        RandomAccessFile aFile = new RandomAccessFile("f:\\file\\01.txt", "rw");
        FileChannel fromChannel = aFile.getChannel();

        RandomAccessFile bFile = new RandomAccessFile("f:\\file\\03.txt", "rw");
        FileChannel toChannel = bFile.getChannel();
        //fromChannel 传输到 toChannel
        long position = 0;
        long size = fromChannel.size();
        fromChannel.transferTo(position, size,toChannel);

        aFile.close();
        bFile.close();
        System.out.println("over!");
    }
}
